/**
  ******************************************************************************
  * @file    usart.h
  * @brief   This file contains all the function prototypes for
  *          the usart.c file
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
  * All rights reserved.</center></h2>
  *
  * This software component is licensed by ST under BSD 3-Clause license,
  * the "License"; You may not use this file except in compliance with the
  * License. You may obtain a copy of the License at:
  *                        opensource.org/licenses/BSD-3-Clause
  *
  ******************************************************************************
  */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __USART_H__
#define __USART_H__

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "main.h"

/* USER CODE BEGIN Includes */
#include "stdint.h"
#include <stdbool.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
/* USER CODE END Includes */

extern UART_HandleTypeDef huart1;

/* USER CODE BEGIN Private defines */
#define UART1_BUFF_SIZE     1024
#define UART2_BUFF_SIZE     256
#define UART3_BUFF_SIZE     256

#define DEBG_UART           USART1
#define DEBG_RX             Uart1Rx

#define DEBUG(format,...) \
do{\
    msgPrintf("[DEBUG  ]%s %s, Line %d :", __FILE__, __FUNCTION__, __LINE__);\
    msgPrintf(format,##__VA_ARGS__);\
    msgPrintf("\r\n");\
}while(0)

#define ERROR(format,...) \
do{\
    msgPrintf("[ERROR  ]%s %s, Line %d :", __FILE__, __FUNCTION__, __LINE__);\
    msgPrintf(format,##__VA_ARGS__);\
    msgPrintf("\r\n");\
}while(0)

#define INFO(format,...) \
do{\
    msgPrintf("[INFO   ]%s %s, Line %d :", __FILE__, __FUNCTION__, __LINE__);\
    msgPrintf(format,##__VA_ARGS__);\
    msgPrintf("\r\n");\
}while(0)

#define WARNING(format,...) \
do{\
    msgPrintf("[WARNING]%s %s, Line %d :", __FILE__, __FUNCTION__, __LINE__);\
    msgPrintf(format,##__VA_ARGS__);\
    msgPrintf("\r\n");\
}while(0)

#define ENTER()                    msgPrintf("===>enter into %s", __FUNCTION__)

typedef struct  
{  
  volatile  uint8_t  RxFlag;
  volatile  uint16_t RxLen;
  uint8_t  *RxBuff;
}USART_RECEIVETYPE;

extern USART_RECEIVETYPE Uart1Rx;
/* USER CODE END Private defines */

void MX_USART1_UART_Init(void);

/* USER CODE BEGIN Prototypes */
void USART1_Init(uint32_t band,uint32_t parity);
void USART1_ReceiveIDLE(void);

void UART_SendByte(USART_TypeDef * Uart,uint8_t data);
void UART_SendData(USART_TypeDef * Uart,uint8_t *buff,uint16_t size);
void UART_SendString(USART_TypeDef * Uart,char *str);
void msgPrintf(char *fmt, ...);
bool UART_ReadRxBuffWithTimeout(USART_RECEIVETYPE uartRx, uint16_t timeout_ms);
void DEBUG_PrintfASCII(uint8_t *pdata, uint16_t length);
void DEBUG_PrintfHEX(uint8_t *pdata, uint16_t length);
/* USER CODE END Prototypes */

#ifdef __cplusplus
}
#endif

#endif /* __USART_H__ */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
